<?php

/**
 * 融合云通信
 */
class UCT {
    private $user;
    private $password;
    private $sign;
    private $usermsgid;

    public function __construct() {
        $this->user='7341039';
        $this->password='510201';
        $this->sign='【摩耶APP】';
        $this->usermsgid='y15738733951';//自定义的唯一标识
    }

    public function send($phone, $content) {
        $url = 'https://open.uctyun.cn/sms/adc_posthandler_new';
        $field['user'] = $this->user;
        $field['password'] = $this->password;
        $submit['desttermid'] =$phone;
        $submit['msgcontent'] =base64_encode($this->sign.$content);
        $submit['desttype'] ='0';
        $submit['usermsgid'] =$this->usermsgid;
        $field['submit'][] = $submit;
        file_put_contents('云短信_'.date("Y-m-d").'.txt',  'URL:'.$url."\r\n",FILE_APPEND);
        file_put_contents('云短信_'.date("Y-m-d").'.txt',  'POSTFIELDS:'.json_encode($field)."\r\n",FILE_APPEND);
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS =>json_encode($field),
            CURLOPT_HTTPHEADER => array(
                'Action: "submitreq"',
                'Content-Type: application/json'
            ),
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        file_put_contents('云短信_'.date("Y-m-d").'.txt',  'Response:'.$response."\r\n",FILE_APPEND);
        if(!$response) return false;
        $result = json_decode($response,true);
        if($result && isset($result['result']) && $result['result']=='0'){
            return true;
        }
        return false;
    }

}